import React from 'react';
import SalaryRefTable from '@/components/SalaryRefTable';
import useSalaryData from '@/components/SalaryRefTable/useSalaryData';
import { ScaleBar } from '@/pages/Recruitment/Hire/Communicate/containers';
import { formatSource } from '@/pages/Recruitment/Hire/Communicate/containers/DiffSalary';
import FormContainer from './FormContainer';

const SalaryRefSection = ({ salaryData = {} }) => {
    const { positionCode = '', companyAreaCode = '', companyCurrencyCode = '' } = salaryData;

    const { dataSource, targetCity, selectCity, selectSalaryData } = useSalaryData({
        positionCode,
        cityDictValue: companyAreaCode,
        filterCompany: ['微微']
    });

    const current = {
        month: salaryData.baseSalaryAmt,
        year: salaryData.totalSalaryAmt
    };

    const { q25, q50, q75 } = selectSalaryData;

    const benchmark = [q25, q50, q75];
    const inputSalary = [current];
    const inputUnit = [companyCurrencyCode];

    const content = (
        <>
            <SalaryRefTable
                initialData={{ dataSource, targetCity }}
                selectCity={selectCity}
                positionCode={positionCode}
            />
            <div style={{ marginTop: 32 }} />
            <ScaleBar
                sourceData={formatSource({ inputSalary, benchmark, type: 'salary', inputUnit, isCurrent: true })}
            />
        </>
    );

    return <FormContainer title="薪资对比">{() => content}</FormContainer>;
};

export default SalaryRefSection;
